home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * $RCSfile: File.cpp $
- * $Revision: 2.7 $
- * $Date: 2004/08/18 21:51:05 $
- * $Author: ssolie $
- *
- *****************************************************************************
- *
- * Copyright (c) 2004 Steven Solie. All Rights Reserved.
- *
- *****************************************************************************
- *
- * File component
- */
- #include "File.h"
-
- #include <dos/dos.h>
- #include <utility/tagitem.h>
-
- #include <proto/dos.h>
-
- #include <cstring>
-
-
- File::File() :
- m_handle(0),
- m_info(0)
- {
- }
-
-
- File::~File()
- {
- if ( m_info != 0 ) {
- IDOS->FreeDosObject(DOS_FIB, m_info);
- }
-
- if ( m_handle != 0 ) {
- IDOS->Close(m_handle);
- }
- }
-
-
- void File::open(const char* name, int32 mode)
- {
- m_handle = IDOS->Open(const_cast<STRPTR>(name), mode);
- if ( m_handle == 0 ) {
- throw dos_error();
- }
-
- if ( mode == MODE_OLDFILE || mode == MODE_READWRITE ) {
- m_info = reinterpret_cast<FileInfoBlock*>(
- IDOS->AllocDosObjectTags(DOS_FIB, TAG_END));
- if ( m_info == 0 ) {
- IDOS->Close(m_handle);
- m_handle = 0;
- IDOS->SetIoErr(ERROR_NO_FREE_STORE);
- throw dos_error();
- }
-
- if ( IDOS->ExamineFH(m_handle, m_info) == DOSFALSE ) {
- IDOS->FreeDosObject(DOS_FIB, m_info);
- IDOS->Close(m_handle);
- m_info = 0;
- m_handle = 0;
- IDOS->SetIoErr(ERROR_NO_FREE_STORE);
- throw dos_error();
- }
- }
- }
-
-
- int32 File::readString(char* buffer, uint32 size)
- {
- if ( IDOS->FGets(m_handle, buffer, size) == 0 ) {
- if ( IDOS->IoErr() == 0 ) {
- return 0;
- }
- else {
- throw dos_error();
- }
- }
-
- return std::strlen(buffer);
- }
-
-
- uint32 File::getLength() const
- {
- return m_info->fib_Size;
- }
-
-
- uint32 File::getProtection() const
- {
- return m_info->fib_Protection;
- }
-
-